#!/bin/bash

CODIS_MAJOR=3
CODIS_MINOR=5
CODIS_PATCH=4

gitsha=`git log --pretty=format:"%H" -1`
if [ $? -ne 0 ]; then
    gitsha ="unknown version gitsha"
fi

compile=`date +"%F %T %Z"`
if [ $? -ne 0 ]; then
    compile="unknown datetime"
fi

goversion=$(go version | sed 's/go version //')
if [ $? -ne 0 ]; then
    compile="unknown go version"
fi

cat << EOF | gofmt > pkg/utils/version.go
package utils

const (
    Version   = "$CODIS_MAJOR.$CODIS_MINOR.$CODIS_PATCH"
    Gitsha = "$gitsha"
    Compile = "$compile"
    GoVersion = "$goversion"
)
EOF

cat << EOF > bin/version
gitsha = $gitsha
compile = $compile
EOF
